﻿/************************************************************************************
 *      Copyright (C) 2008 supesoft.com,All Rights Reserved						    *
 *      File:																		*
 *				FrameSystemInfo.cs                                        			*
 *      Description:																*
 *				 系统信息操作类    												    *
 *      Author:																		*
 *				Lzppcc														        *
 *				Lzppcc@hotmail.com													*
 *				http://www.supesoft.com												*
 *      Finish DateTime:															*
 *				2007年8月6日														*
 *      History:																	*
 ***********************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using BingZi.HY.Core;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Net;
using System.Collections;
using System.Reflection;
using BingZi.HY.Core;

namespace BingZi
{
    /// <summary>
    /// 系统信息操作类
    /// </summary>
    public class FrameSystemInfo
    {
        /// <summary>
        /// 系统信息类
        /// </summary>
        public static sys_SystemInfo GetSystemInfoTable = new sys_SystemInfo();
        /// <summary>
        /// 构造函数
        /// </summary>
        static FrameSystemInfo()
        {

            if (!(GetSystemInfoTable != null && GetSystemInfoTable.SystemID > 1))
            {

                sys_SystemInfo si = new sys_SystemInfo();
                if (sys_SystemInfo.FindCount() == 0 )
                {
                    //si.ConfigDataTable = new sys_ConfigDataTable();
                   
                    si.Insert();
                }
                else
                {
                    List<sys_SystemInfo> lst = sys_SystemInfo.FindAll();
                    si = lst[0];
                    //    ////更新新加配置
                    //    //sys_ConfigDataTable sys_ConfigDB = si.ConfigDataTable;
                    //    //sys_ConfigDataTable sys_Config = new sys_ConfigDataTable();
                    //    ////foreach (PropertyInfo pi in new sys_ConfigDataTable().GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                    //    //foreach (PropertyInfo pi in sys_ConfigDB.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                    //    //{
                    //    //    if (pi.GetValue(sys_ConfigDB, null) == null)
                    //    //    {
                    //    //        pi.SetValue(sys_ConfigDB, pi.GetValue(sys_Config, null), null);
                    //    //    }
                    //    //}
                }
                GetSystemInfoTable = si;
                //GetSystemInfoTable = si.ConfigDataTable;
            }
 
            BingZiPermission.InitStat = true;
        }

        /// <summary>
        /// 序列化sys_BingZiInfoTable类
        /// </summary>
        /// <param name="it">sys_BingZiInfoTable类</param>
        /// <returns>byte[]字节流</returns>
        public static byte[] Serializable_sys_BingZiInfoTable(sys_BingZiInfoTable it)
        {
            IFormatter formatter = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            byte[] b;
            formatter.Serialize(ms, it);
            ms.Position = 0;
            b = new byte[ms.Length];
            ms.Read(b, 0, b.Length);
            ms.Close();
            return b;
        }

        /// <summary>
        /// 反序列化字节为sys_BingZiInfoTable类
        /// </summary>
        /// <param name="BytArray">字节流</param>
        /// <returns>sys_BingZiInfoTable类</returns>
        public static sys_BingZiInfoTable Deserialize_sys_BingZiInfoTable(byte[] BytArray)
        {
            IFormatter formatter = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            ms.Write(BytArray, 0, BytArray.Length);
            ms.Position = 0;
            sys_BingZiInfoTable it = formatter.Deserialize(ms) as sys_BingZiInfoTable;
            return it;
        }

     

        /// <summary>
        /// 获取BingZi名称
        /// </summary>
        public static string BingZiVerName
        {
            get
            {
                string FrameName = "";
                if (GetSystemInfoTable.S_BingZiInfo.S_Licensed != "" && GetSystemInfoTable.S_BingZiInfo.S_Type != S_VersionType.Beta)
                    FrameName = GetSystemInfoTable.S_BingZiInfo.S_Name + " " + GetSystemInfoTable.S_BingZiInfo.S_Version + " " + S_VersionType.Release.ToString();
                else
                    FrameName = GetSystemInfoTable.S_BingZiInfo.S_Name + " " + GetSystemInfoTable.S_BingZiInfo.S_Version + " " + GetSystemInfoTable.S_BingZiInfo.S_Type.ToString();
                return FrameName;
            }

        }
    }
}
